using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;

public class SortListByTextAsc : IComparer
{
    public int Compare(object a, object b)
    {
        ListItem itemA = (ListItem)a;
        ListItem itemB = (ListItem)b;
        if (itemA.Text.CompareTo(itemB.Text) > 0)
            return 1;
        if (itemA.Text.CompareTo(itemB.Text) < 0)
            return -1;
        else
            return 0;
    }
}

public class SortListByIDDesc : IComparer
{
    public int Compare(object a, object b)
    {
        ListItem itemA = (ListItem)a;
        ListItem itemB = (ListItem)b;
        if (Convert.ToInt32(itemA.Value) < Convert.ToInt32(itemB.Value))
            return 1;
        if (Convert.ToInt32(itemA.Value) > Convert.ToInt32(itemB.Value))
            return -1;
        else
            return 0;
    }
}

public class SortListByLabelDesc : IComparer
{
    public int Compare(object a, object b)
    {
        try
        {
            ListItem itemA = (ListItem)a;
            ListItem itemB = (ListItem)b;
            //if (itemA == null)
            //    return -1;
            //if (itemB == null)
            //    return 1;
            String labelA = Convert.ToString(itemA.Attributes["label"]);
            String labelB = Convert.ToString(itemB.Attributes["label"]);
            //if (labelA == null)
            //    return -1;
            //if (labelB == null)
            //    return 1;
            if (labelA.CompareTo(labelB) > 0)
                return -1;
            if (labelA.CompareTo(labelB) < 0)
                return 1;
            else
                return 0;
        }
        catch (Exception ex)
        {
            return 0;
        }
    }
}
